package v1

import (
	"github.com/gin-gonic/gin"
	"missC/model"
	"missC/utils/er"
)

// AddSort 添加分类
func AddSort(c *gin.Context) {
	var data model.Sort
	_ = c.ShouldBindJSON(&data)

	//查询重复是否有分类
	code := model.GetSort(data.Name)
	if code == 200 {
		//添加分类
		code = model.AddSort(&data)
		c.JSON(200, gin.H{
			"code": code,
			"data": data,
			"msg":  er.GetErr(code),
		})
		return
	}
	//重复分类返回
	c.JSON(200,
		gin.H{
			"status":  code,
			"data":    data,
			"message": er.GetErr(code),
		},
	)
}
